package com.slicktechnologies.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.itextpdf.text.log.SysoCounter;
import com.simplesoftwares.client.library.libservice.SMSService;

public class SmsServiceImpl extends RemoteServiceServlet implements SMSService
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 9205550162359635493L;

	@Override
	public void sendSms(String phoneNumber, String Msg, String senderId) {
		System.out.println("a");
		String url = "http://bhashsms.com/api/sendmsg.php";
		String charset = "UTF-8";
		String user = "9764746709";
		String pass = "4a5c9b8";
		String sender = "TESTTO";
		String phone=""+phoneNumber;
		String text=""+Msg;
		String priority="ndnd";
		String smstype ="normal";
		String querry="";
		
		try {
			querry=String.format("user=%s&pass=%s&sender=%s&phone=%s&text=%s&priority=%s&stype=%s", 
				     URLEncoder.encode(user, charset), 
				     URLEncoder.encode(pass, charset),
				     URLEncoder.encode(sender, charset),
				     URLEncoder.encode(phone, charset),
				     URLEncoder.encode(text, charset),
				     URLEncoder.encode(priority, charset),
				     URLEncoder.encode(smstype, charset));
			System.out.println("String "+querry);
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		//String urls="http://bhashsms.com/api/sendmsg.php?user=&pass=********&sender=Sender ID&phone=Mobile No&text=Test SMS&priority=Priority&stype=smstype";
		
		try {
			URLConnection connection = new URL(url + "?" + querry).openConnection();
			connection.setRequestProperty("Accept-Charset", charset);
			InputStream response = connection.getInputStream();
			
		} catch (MalformedURLException e) {
			System.out.println("Ajay");
			e.printStackTrace();
		} catch (IOException e) {
			System.out.println("Ajay---");
			e.printStackTrace();
		}
		
		System.out.println("Pradnya");
		
	}

}
